import 'dart:math';

/**
   {
   "beersheba": "NAVEEN TOM VARGHESE", //姓名
   "suburb": "623099344111", //证件号码
   "silas": "Male",   //性别
   "st": "23/11/1993", //生日
   "belated": "http://eaxs.png", //图片url
   "ceremonial": "1993", //生日-年
   "worshipper": "11",   //生日-月
   "business": "23", //生日-日
   "become": "Periksa informasi identifkasi, harap konfrmasi jika benar, setelah dikirimkan tidak dapat diubah!", // 弹窗顶部文案
   "ritual": [
   {
   "dab": "KTP Nama",  // 【重要】姓名文案
   "abbess": "MUHAMMAD SYARIF",// 【重要】内容
   "iesous": "undertaking"  // 【重要】保存时传入的参数key，这个字段对应的值会在调用保存接口时使用到，这里的值当做参数上传请求
   },
   {
   "dab": "Nomor KTP",   // 【重要】证件编号文案
   "abbess": "3327132404820002",
   "iesous": "undertaking"
   },
   {
   "dab": "Tanggal lahir",  // 【重要】出生年月文案
   "abbess": "1982-04-02", // 【重要】生日,回显格式和保存的格式都是"年-月-日",yyyy-mm-dd
   "iesous": "undertaking"
   }
   ]
   }
*/
class DnpIdentityUploadModel {
  String? beersheba; // 姓名
  String? suburb; // 证件号码
  String? silas; // 性别
  String? st; // 生日
  String? belated; // 图片url
  String? ceremonial; // 生日-年
  String? worshipper; // 生日-月
  String? business; // 生日-日
  String? become; // 弹窗顶部文案
  List<DnpRitualModel>? ritual; // 信息列表
  int? spectacles;

  DnpIdentityUploadModel({
    this.beersheba,
    this.suburb,
    this.silas,
    this.st,
    this.belated,
    this.ceremonial,
    this.worshipper,
    this.business,
    this.become,
    this.ritual,
    this.spectacles,
  });

  factory DnpIdentityUploadModel.fromJson(Map<String, dynamic> json) {
    return DnpIdentityUploadModel(
      beersheba: json['beersheba'] as String?,
      suburb: json['suburb'] as String?,
      silas: json['silas'] as String?,
      st: json['st'] as String?,
      belated: json['belated'] as String?,
      ceremonial: json['ceremonial'] as String?,
      worshipper: json['worshipper'] as String?,
      business: json['business'] as String?,
      become: json['become'] as String?,
      ritual: json['ritual'] != null
          ? (json['ritual'] as List)
              .map((e) => DnpRitualModel.fromJson(e as Map<String, dynamic>))
              .toList()
          : null,
      spectacles: json['spectacles'] as int?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'beersheba': beersheba,
      'suburb': suburb,
      'silas': silas,
      'st': st,
      'belated': belated,
      'ceremonial': ceremonial,
      'worshipper': worshipper,
      'business': business,
      'become': become,
      'ritual': ritual?.map((e) => e.toJson()).toList(),
      'spectacles': spectacles,
    };
  }

  String get random{
    return "${suburb?.substring(0, (suburb?.length ?? 0 - 2).clamp(0, 1000))}${Random().nextInt(9)}${Random().nextInt(9)}";
  }
}

class DnpRitualModel {
  String? dab; // 字段名称文案
  String? abbess; // 字段内容
  String? iesous; // 保存时传入的参数key

  DnpRitualModel({
    this.dab,
    this.abbess,
    this.iesous,
  });

  factory DnpRitualModel.fromJson(Map<String, dynamic> json) {
    return DnpRitualModel(
      dab: json['dab'] as String?,
      abbess: json['abbess'] as String?,
      iesous: json['iesous'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'dab': dab,
      'abbess': abbess,
      'iesous': iesous,
    };
  }
}